#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

bool visite[20][20];
int dx[4] = { 0, 0 , 1, -1 };
int dy[4] = { 1 , -1 , 0 , 0 };
int ret = 0;
int m, n;

void dfs(vector<vector<int>>& grid, int row, int col)
{
    if (grid[row][col] == 2)
    {
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (grid[i][j] == 0 && visite[i][j] == false)
                    return;
            }
        }
        ret++;
    }

    for (int i = 0; i < 4; ++i)
    {
        int x = row + dx[i];
        int y = col + dy[i];

        if (x >= 0 && x < grid.size() && y >= 0 && y < grid[0].size()
            && visite[x][y] == false && grid[x][y] != -1)
        {
            visite[x][y] = true;
            dfs(grid, x, y);
            visite[x][y] = false;
        }
    }
}

int uniquePathsIII(vector<vector<int>>& grid) {
    m = grid.size();
    n = grid[0].size();

    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (grid[i][j] == 1)
            {
                visite[i][j] = true;
                dfs(grid, i, j);
                return ret;
            }
        }
    }
    return -1;
}

int main()
{

	return 0;
}